$(function(){

	//左侧楼层导航
	
	function scrollToTop(parentId) {
		var indexWrapper = document.getElementById(parentId),
			indexNav = document.getElementById('indexNav'),
			iscrollTop = document.documentElement.scrollTop || document.body.scrollTop,
			wrapperLeft = indexWrapper.offsetLeft,
			wrapperWidth = indexWrapper.clientWidth,
			navWidth = indexNav.offsetWidth,
			indexNavR = document.getElementById('indexNavR'),
			timer = null;


			// 控制开始的时候左侧悬浮导航的位置
			indexNav.style.left = parseInt(wrapperLeft - 100 - 10) + 'px';
			indexNavR.style.left = parseInt(wrapperLeft + wrapperWidth + 10) + 'px';

			// 控制右侧悬浮导航位置


			// 控制返回顶部的缓动函数
			$("#indexNav li:last").click(function() {
				$("body").stop(true, true).animate({
					"scrollTop" : "0"
				},600);
			})

			window.onscroll = function() {
				var iscrollTop = document.documentElement.scrollTop || document.body.scrollTop;
				if(iscrollTop>= 1000) {
					$(indexNav).css({
						"opacity" : "1"
					});

					$(indexNavR).css({
						"opacity" : "1"
					});
				} else {
					
					$(indexNav).css({
						"opacity" : "0"
					});
					$(indexNavR).css({
						"opacity" : "0"
					})
				}
				
				$("#indexNav ul li").click(function(){
					var index = $(this).index(),
						dis = 1140 + parseInt(index * 869);
						iscrollTop = dis;
						document.documentElement.scrollTop = iscrollTop;
						document.body.scrollTop = iscrollTop;
				})
			}
			// 当视口宽度改变的时候控制左侧悬浮导航的位置
			window.onresize = function() {
				var wrapperLeft = indexWrapper.offsetLeft,
					navWidth = indexNav.offsetWidth;
				indexNav.style.left = parseInt(wrapperLeft - 100) + 'px';
				indexNavR.style.left = parseInt(wrapperLeft + wrapperWidth + 10) + 'px';

			}
	}
	scrollToTop('indexWrapper');

	// 楼层功能函数

    var parentIndex = $(".index-floor .index-floor1").index();
	$(" .index-floor1-hover li").mouseover(function(){
		var index = $(this).index();
        var i = $(this).parents(".index-floor1").index();
        $(".index-floor1-hover").eq(i).children("a").css({
			"display" : "none"
		});
        $(".index-floor1-hover").eq(i).children("a").eq(index).css({
			"display" : "block"
		});
        $(".index-floor1-hover").eq(i).siblings().children(".floorone-price").addClass("index-floor1-hidden");
        $(".index-floor1-hover").eq(i).siblings().children(".floorone-price").eq(index).removeClass("index-floor1-hidden");
	})

	// 首页轮播滚动函数功能 start

	var ulLength = $(".index-box-ad-content ul").length - 1,
		boxWidth = $(".index-box-ad-content ul").outerWidth(),
		totleWidth = boxWidth * (ulLength + 1),
		contentWidth = $(".index-box-ad-content").outerWidth();
	$(".index-box-ad-content").width(totleWidth);
	
	//楼层houver 切换
	$(".index-floor1-tit a").mouseover(function() {
		$(this).siblings("strong").css({
			"background" : "url(/themes/mmj/assets/images/icon.png" + ") -51px -13px"
		});
	});
	$(".index-floor1-tit a").mouseout(function() {
		$(this).siblings("strong").css({
			"background" : "url(/themes/mmj/assets/images/icon.png" + ") -51px 0px"
		});
	})

	$(".index-bar p").mouseover(function() {
		$(this).siblings(".index-ad-arrow").css({
			"background" : "url(/themes/mmj/assets/images/arrow-r_1.png" + ")"
		});
	});
	$(".index-bar p").mouseout(function() {
		$(this).siblings(".index-ad-arrow").css({
			"background" : "url(/themes/mmj/assets/images/arrow-r.png" + ")"
		});
	})

	function moveStart(){
			var i = 0,
				dis = null,
				moveJudge = true;
		function movePic() {
			i--;
			if(i < -ulLength) {
				i = 0;
				$(".index-box-ad-content").animate({
					"left" : 0
				},600);
			} else {
				dis = 570 * i;
				$(".index-box-ad-content").animate({
					"left" : dis
				},600);
			}
		}

			timer = setInterval(movePic, 2500);
			
		$(".index-box-ad-l").mouseover(function() {
			clearInterval(timer);
		});

		$(".index-box-ad-l").mouseout(function() {
			timer = setInterval(movePic, 2500);
		});

		// 左侧点击功能
		$("#arrowLeft").click(function() {
			clearInterval(timer);
			if(i == -ulLength) {
				i = 0;
				$(".index-box-ad-content").stop(true, true).animate({
					"left" : "0"
				},600)
			} else {
				i--;
				dis = 570 * i;
				$(".index-box-ad-content").stop(true, true).animate({
					"left" : dis
				},600);
			}
		});
		
		// 右侧点击功能
			
		$("#arrowRight").click(function() {
			clearInterval(timer);
			if(i == -ulLength) {
				i = 0;
				$(".index-box-ad-content").stop(true, true).animate({
					"left" : "0"
				},600)
			} else {
				i--;
				dis = 570 * i;
				$(".index-box-ad-content").stop(true, true).animate({
					"left" : dis
				},600);
			}
		});
	}

	moveStart();
	// 首页轮播滚动函数功能 end


	// 支持placeholder属性
	  var JPlaceHolder = {
    //检测
    _check : function(){
        return 'placeholder' in document.createElement('input');
    },
    //初始化
    init : function(){
        if(!this._check()){
            this.fix();
        }
    },
    //修复
    fix : function(){
        jQuery(':input[placeholder]').each(function(index, element) {
            var self = $(this), txt = self.attr('placeholder');
            self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
            var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
            var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top="6px", height:h, lienHeight:h, paddingLeft:paddingleft, color:'#aaa'}).appendTo(self.parent());
            self.focusin(function(e) {
                holder.hide();
            }).focusout(function(e) {
                if(!self.val()){
                    holder.show();
                }
            });
            holder.click(function(e) {
                holder.hide();
                self.focus();
            });
        });
    }
};
//执行
jQuery(function(){
    JPlaceHolder.init();  
});

})